public class Test {
    public static void main(String[] args) {
        System.out.println(fib(5))；
        System.out.println(fib(6));
        System.out.println(fib(40));
        System.out.println(fib2(5));
        System.out.println(fib2(6));
        System.out.println(fib2(40));
    }

    public static int fib2(int n){
        if (n == 1 ){
            return 0;
        }
        if (n == 2){
            return 1;
        }
        int f1 = 0;
        int f2 = 1;
        int f3 = 1;
        for (int i = 3;i <= n;i++){
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }

    public static int fib(int n){
        if (n == 1){
            return 0;
        }
        if (n == 2){
            return 1;
        }
        return fib(n - 1) + fib(n - 2);
    }

    public static int add(int n){
        if (n < 10){
            return n;
        }
        return n % 10 + add(n / 10);
    }

    public static int sum(int n){
        if (n == 1){
            return 1;
        }
        return n + sum(n - 1);
    }

    public static void print(int n) {
        if (n < 10){
            System.out.println(n);
            return;
        }
        print(n / 10);
        System.out.println(n % 10);
    }

    public static int fac(int n) {
        if (n == 1){
            return 1;
        }
        int tem = n * fac(n-1);
        return tem;
    }

    public static void func(int a) {
        if (a == 1){
            return;
        }
        System.out.println(a);
        func(a-1);
    }
}



